/**
 * <p>Title: ServiceZMCF27.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-9-23 下午05:03:11  张志芳  Create
 *</pre>
 */
package com.baosight.sczx.zm.cf.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.zm.cf.domain.ZMCFContactReceive;

/**
 * 接收部门
 * <p>Title: ServiceZMCF27.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-9-23 下午05:03:11  张志芳  Create
 *</pre>
 */
public class ServiceZMCF27 extends ServiceEPBase {
	/**
	 * 初始化方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS17</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-6下午01:56:26 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(Department.getInstance().getConstructionUnit(false));//部门
		return outInfo;
	}

	/**
	 * 查询方法
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS17</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-6下午01:56:44 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		String fdContactlistId = inInfo.getString("fdContactlistId");
		StaticTools.setQueryParameters(inInfo, "fdContactlistId", fdContactlistId, true);//添加查询条件
		
		EiInfo outInfo = super.query(inInfo, "ZMCFContactReceive.query", new ZMCFContactReceive());
		return outInfo;
	}
	
	/**
	 * 新增方法
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS17</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-6下午01:56:59 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings("unchecked")
	@Override
	public EiInfo insert(EiInfo inInfo) {	
		List<ZMCFContactReceive> list = null;
		for(int i = 0; i < inInfo.getBlock(EiConstant.resultBlock).getRowCount(); i++)
		{
			//判断部门是否重复
			if(list == null)
			{
				String id = inInfo.getBlock(EiConstant.resultBlock).getCellStr(i, "fdContactlistId");
				Map<String, String> map = new HashMap<String, String>();
				map.put("fdContactlistId", id);
				list = dao.query("ZMCFContactReceive.query", map);
			}
			for(ZMCFContactReceive tmp : list)
			{
				if(tmp.getFdReceiveId().equals(inInfo.getBlock(EiConstant.resultBlock).getCellStr(i, "fdReceiveId")))
				{
					inInfo.setStatus(-1);
					inInfo.setMsg("不能重复添加，请去掉已添加过的接收部门！");
					return inInfo;
				}
			}
			
			inInfo.getBlock(EiConstant.resultBlock).setCell(i, "fdKeyId", TablePk.getInstance().getNextValue("T_CF_CONTACTRECEIVE"));			
		}		
		EiInfo outinfo = super.insert(inInfo, "ZMCFContactReceive.insert");
		return outinfo;
	}
	
	/**
	 * 删除方法
	 * <p>Function: delete</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS17</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-6下午01:57:29 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {		
		EiInfo _temp = super.delete(inInfo, "ZMCFContactReceive.delete");		
        EiInfo outInfo = this.query(inInfo);
        outInfo.setMsg(_temp.getMsg());
        outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}
}
